package com.ruoyi.hatha.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hatha.domain.PRooms;
import com.ruoyi.hatha.service.IPRoomsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教室管理Controller
 * 
 * @author ruoyi
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/hatha/rooms")
public class PRoomsController extends BaseController
{
    @Autowired
    private IPRoomsService pRoomsService;

    /**
     * 查询教室管理列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:list')")
    @GetMapping("/list")
    public TableDataInfo list(PRooms pRooms)
    {
        startPage();
        List<PRooms> list = pRoomsService.selectPRoomsList(pRooms);
        return getDataTable(list);
    }

    @GetMapping("/listall")
    public AjaxResult listall(PRooms pRooms)
    {
        List<PRooms> list = pRoomsService.selectPRoomsList(pRooms);
        return AjaxResult.success(list);
    }

    /**
     * 导出教室管理列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:export')")
    @Log(title = "教室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PRooms pRooms)
    {
        List<PRooms> list = pRoomsService.selectPRoomsList(pRooms);
        ExcelUtil<PRooms> util = new ExcelUtil<PRooms>(PRooms.class);
        util.exportExcel(response, list, "教室管理数据");
    }

    /**
     * 获取教室管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pRoomsService.selectPRoomsById(id));
    }

    /**
     * 新增教室管理
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:add')")
    @Log(title = "教室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PRooms pRooms)
    {
        return toAjax(pRoomsService.insertPRooms(pRooms));
    }

    /**
     * 修改教室管理
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:edit')")
    @Log(title = "教室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PRooms pRooms)
    {
        return toAjax(pRoomsService.updatePRooms(pRooms));
    }

    /**
     * 删除教室管理
     */
    @PreAuthorize("@ss.hasPermi('hatha:rooms:remove')")
    @Log(title = "教室管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pRoomsService.deletePRoomsByIds(ids));
    }
}
